package com.lagou.service.impl;

import com.lagou.dao.IUserDao;
import com.lagou.dao.impl.UserDaoImpl;
import com.lagou.service.IUserService;
import com.lagou.utils.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

/**
 * @program: spring
 * @description:
 * @author: Mr.Wang
 * @create: 2020-12-15 10:51
 **/
@Service("userService")
public class UserServiceImpl implements IUserService {
	@Autowired
	private IUserDao userDao;

	public UserServiceImpl(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void save() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
		//普通new方法创建
		//IUserDao userDao = new UserDaoImpl();
		// 反射创建
		//IUserDao userDao = (IUserDao)Class.forName("com.lagou.dao.impl.UserDaoImpl").newInstance();
		//反射+配置文件创建
		//IUserDao userDao = (IUserDao)BeanFactory.getBean("userDao");

		//spring方式
/*		ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		IUserDao userDao = (IUserDao)classPathXmlApplicationContext.getBean("userDao");*/

		//依赖注入
		userDao.save();
	}
}
